package com.joyoung.datarespository;


import com.joyoung.cons.Cons;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.Map;

/**
 * Created by Administrator on 2017\7\27 0027.
 */

public class UserBuilder {

    private JSONObject jsonObject = new JSONObject();
    private JSONObject mob_data = new JSONObject();

    private boolean hasData = false;


    public UserBuilder() {
    }

    public UserBuilder action(String action) throws Exception {
        jsonObject.put("op_action", action);
        jsonObject.put("sessionkey", Cons.sessionkey);
        return this;
    }



    public UserBuilder uname(String uname) throws Exception {
        jsonObject.put("uname", uname);
        return this;
    }

    public UserBuilder tagname(String tagname) throws Exception {
        jsonObject.put("tagname", tagname);
        return this;
    }

    public UserBuilder dcode(String dcode) throws Exception {
        jsonObject.put("dcode", dcode);
        return this;
    }

    public UserBuilder devid(String devid) throws Exception {
        jsonObject.put("devid", devid);
        return this;
    }

    public UserBuilder id(String id) throws Exception {
        jsonObject.put("id", id);
        return this;
    }

    public UserBuilder type(String type) throws Exception {
        jsonObject.put("type", type);
        return this;
    }

    public UserBuilder mobilenum(String mobilenum) throws Exception {
        jsonObject.put("mobilenum", mobilenum);
        return this;
    }

    public UserBuilder uid(String uid) throws Exception {
        jsonObject.put("uid", uid);
        return this;
    }

    public UserBuilder codetype(String codetype) throws Exception {
        jsonObject.put("codetype", codetype);
        return this;
    }

    public UserBuilder passwd(String passwd) throws Exception {
        jsonObject.put("passwd", passwd);
        return this;
    }

    public UserBuilder nickname(String nickname) throws Exception {
        jsonObject.put("nickname", nickname);
        return this;
    }

    public UserBuilder identifyingcode(String identifyingcode) throws Exception {
        jsonObject.put("identifyingcode", identifyingcode);
        return this;
    }

    public UserBuilder content(String content) throws Exception {
        jsonObject.put("content", content);
        return this;
    }

    public UserBuilder contentId(String contentId) throws Exception {
        jsonObject.put("contentId", contentId);
        return this;
    }

    public UserBuilder description(String description) throws Exception {
        jsonObject.put("description", description);
        return this;
    }

    public UserBuilder start(int start) throws Exception {
        jsonObject.put("start", start);
        return this;
    }
    public UserBuilder limit(int limit) throws Exception {
        jsonObject.put("limit", limit);
        return this;
    }


    public UserBuilder gender(String gender) throws Exception {
        jsonObject.put("gender", gender);
        return this;
    }

    public UserBuilder birthdate(String birthdate) throws Exception {
        jsonObject.put("birthdate", birthdate);
        return this;
    }

    public UserBuilder oldpasswd(String oldpasswd) throws Exception {
        jsonObject.put("oldpasswd", oldpasswd);
        return this;
    }

    public UserBuilder newpasswd(String newpasswd) throws Exception {
        jsonObject.put("newpasswd", newpasswd);
        return this;
    }

    public UserBuilder configs(Map<String, String> map) throws Exception {

        JSONArray configs = new JSONArray();
        for (String key : map.keySet()) {
            JSONObject config = new JSONObject();
            config.put("name", key);
            config.put("value", map.get(key));
            configs.put(config);
        }
        jsonObject.put("configs", configs);

        return this;
    }


    public UserBuilder page(int start, int limit) throws Exception {
        JSONObject page = new JSONObject();
        page.put("start", start);
        page.put("limit", limit);
        jsonObject.put("page", page);
        return this;
    }




    public String build() throws Exception {
        //添加 mob_data
        mob_data.put("mobile_id", Cons.msdnForMobileId);
        jsonObject.put("mob_data", mob_data);

        return jsonObject.toString();
    }

}
